import { mapState } from 'vuex';
import store from './index.js';

// 尝试将用户在根目录中的store/index.js的vuex的state变量，全部加载到全局变量中
let $lzStoreKey = [];
try {
    $lzStoreKey = store.state ? Object.keys(store.state) : [];
} catch (e) {
    console.log('vuexStore catch');
    console.log(e);
    console.log('vuexStore catch');
}

module.exports = {
    created() {
        uni.$lz.vuex = (key, value) => {
            this.$store.commit('$lzStore', {
                key,
                value
            });
        };
    },
    computed: {
        // 将vuex的state中的所有变量，解构到全局混入的mixin中
        ...mapState($lzStoreKey)
    }
};
